package com.timmy.bluetooth.utils;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;

import static android.content.Context.MODE_PRIVATE;

/**
 * SharedPreferences 工具类
 */
public class ShareUtil {

    public static void SaveTimeState(Context context, boolean hasChange){
        SharedPreferences sharedPreferences=context.getSharedPreferences("timeChange", MODE_PRIVATE);
        SharedPreferences.Editor editor=sharedPreferences.edit();
        editor.putBoolean("hasChange",hasChange);
        editor.commit();
    }

    public static boolean GetTimeState(Context context){
        SharedPreferences sharedPreferences=context.getSharedPreferences("timeChange", MODE_PRIVATE);
        boolean b=sharedPreferences.getBoolean("hasChange",false);
        return b;
    }


    public static void SaveStarTime(Context context,long time){
        SharedPreferences sharedPreferences=context.getSharedPreferences("starScore", MODE_PRIVATE);
        SharedPreferences.Editor editor=sharedPreferences.edit();
        editor.putLong("star",time);
        editor.commit();
    }

    public static long GetStarTime(Context context){
        SharedPreferences sharedPreferences=context.getSharedPreferences("starScore", MODE_PRIVATE);
        long time=sharedPreferences.getLong("star",0);
        return  time;
    }


    public static void SaveExitSpeed(Context context, boolean isNomal){
        SharedPreferences sharedPreferences=context.getSharedPreferences("exitSpeed", MODE_PRIVATE);
        SharedPreferences.Editor editor=sharedPreferences.edit();
        editor.putBoolean("isNomal",isNomal);
        editor.commit();
    }

    public static boolean getExitSpeed(Context context){
        SharedPreferences sharedPreferences=context.getSharedPreferences("exitSpeed", MODE_PRIVATE);
        boolean b=sharedPreferences.getBoolean("isNomal",false);
        return b;
    }

    public static void SaveWeekUsed(Context context,long time){
        SharedPreferences sharedPreferences=context.getSharedPreferences("weekTime", MODE_PRIVATE);
        SharedPreferences.Editor editor=sharedPreferences.edit();
        editor.putLong("weekUsed",time);
        editor.commit();
    }

    public static long GetWeekUsed(Context context){
        SharedPreferences sharedPreferences=context.getSharedPreferences("weekTime", MODE_PRIVATE);
        long time=sharedPreferences.getLong("weekUsed",0);
        return time;
    }

    public static void SaveLover(Context context,String name){
        SharedPreferences sharedPreferences=context.getSharedPreferences("lover", MODE_PRIVATE);
        SharedPreferences.Editor editor=sharedPreferences.edit();
        editor.putString("girlFriend",name);
        editor.commit();
    }

    public static String GetLover(Context context){
        SharedPreferences sharedPreferences=context.getSharedPreferences("lover", MODE_PRIVATE);
        String name=sharedPreferences.getString("girlFriend","");
        return name;
    }


    public static void SaveMac(Activity context, String mac){
        SharedPreferences sharedPreferences=context.getSharedPreferences("Device", MODE_PRIVATE);
        SharedPreferences.Editor editor=sharedPreferences.edit();
        editor.putString("mac", mac);
        editor.commit();
    }

    public static String GetMac(Activity context){
        SharedPreferences sharedPreferences=context.getSharedPreferences("Device", MODE_PRIVATE);
        String mac=sharedPreferences.getString("mac","");
        return mac;
    }


    public static boolean getConnectState(Activity context){
        SharedPreferences sharedPreferences = context.getSharedPreferences("hasBle", MODE_PRIVATE);
        return sharedPreferences.getBoolean("isConnect", false);
    }

    public static void updateConnectStatus(Activity context,boolean isconnect){
        SharedPreferences sharedPreferences = context.getSharedPreferences("hasBle", MODE_PRIVATE);
        SharedPreferences.Editor editor = sharedPreferences.edit();
        editor.putBoolean("isConnect", isconnect);
        editor.commit();
    }


    public static void SaveVersion(Context activity,String version){
        SharedPreferences sharedPreferences=activity.getSharedPreferences("Version", MODE_PRIVATE);
        SharedPreferences.Editor editor=sharedPreferences.edit();
        editor.putString("version", version);
        editor.commit();
    }

    public static String GetVersion(Context activity){
        SharedPreferences sharedPreferences=activity.getSharedPreferences("Version", MODE_PRIVATE);
        String version=sharedPreferences.getString("version","");
        return version;
    }

    public static void SaveUpdateState(Activity activity,boolean isNew){
        SharedPreferences sharedPreferences=activity.getSharedPreferences("update", MODE_PRIVATE);
        SharedPreferences.Editor editor=sharedPreferences.edit();
        editor.putBoolean("isNew",isNew);
        editor.commit();
    }

    public static boolean GetUpdateState(Context activity){
        SharedPreferences sharedPreferences=activity.getSharedPreferences("update", MODE_PRIVATE);
        boolean isNew=sharedPreferences.getBoolean("isNew",false);
        return isNew;
    }

    public static void SaveDeviceState(Activity activity,boolean isAction){
        SharedPreferences sharedPreferences=activity.getSharedPreferences("action", MODE_PRIVATE);
        SharedPreferences.Editor editor=sharedPreferences.edit();
        editor.putBoolean("isAction",isAction);
        editor.commit();
    }

    public static boolean GetDeviceState(Context activity){
        SharedPreferences sharedPreferences=activity.getSharedPreferences("action", MODE_PRIVATE);
        boolean isAction=sharedPreferences.getBoolean("isAction",false);
        return isAction;
    }

    /**
     *  保存互动时， 控制方的身份
     * @param activity
     * @param userId
     * @return
     */
    public static void SaveInterActionBoy(Context activity,int userId){
        SharedPreferences sharedPreferences=activity.getSharedPreferences("interAction_boy", MODE_PRIVATE);
        SharedPreferences.Editor editor=sharedPreferences.edit();
        editor.putInt("userId",userId);
        editor.commit();
    }

    public static int GetInterActionBoy(Context activity){
        SharedPreferences sharedPreferences=activity.getSharedPreferences("interAction_boy", MODE_PRIVATE);
        return sharedPreferences.getInt("userId",-1);
    }

    /**
     *   保存互动，  默认被控制方的身份
     * @param activity
     * @param userId
     */
    public static void SaveDefalutObject(Context activity,int userId,String userName){
        SharedPreferences sharedPreferences=activity.getSharedPreferences("interAction_girl", MODE_PRIVATE);
        SharedPreferences.Editor editor=sharedPreferences.edit();
        editor.putInt("userId",userId);
        editor.putString("userName",userName);
        editor.commit();
    }

    public static int GetDefalutObject_userId(Context activity){
        SharedPreferences sharedPreferences=activity.getSharedPreferences("interAction_girl", MODE_PRIVATE);
        return sharedPreferences.getInt("userId",-1);
    }

    public static String GetDefalutObject_userName(Context activity){
        SharedPreferences sharedPreferences=activity.getSharedPreferences("interAction_girl", MODE_PRIVATE);
        return sharedPreferences.getString("userName","");
    }

    public static void SaveVersionInfo(Context activity,String AppInfoJson){
        SharedPreferences sharedPreferences=activity.getSharedPreferences("AppInfoJson", MODE_PRIVATE);
        SharedPreferences.Editor editor=sharedPreferences.edit();
        editor.putString("AppInfoJson",AppInfoJson);
        editor.commit();
    }

    public static String GetVersionInfo(Context activity){
        SharedPreferences sharedPreferences = activity.getSharedPreferences("AppInfoJson", MODE_PRIVATE);
        return sharedPreferences.getString("AppInfoJson","");
    }
}
